#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time     : 2021/6/15 11:33
# @Author   : chengfeng
# @Email    : chengfeng@inhand.com.cn
# @File     : main.py

import pytest
import os
import sys
import json
import logging
from Common.publicMethod import PublicMethod

log = logging.getLogger()

if __name__ == "__main__":
    version = '2.0.0.r13953'
    root_dir = os.path.dirname(__file__)
    report_dir = os.path.abspath(os.path.join(root_dir, "Report"))
    PublicMethod.create_dirs(report_dir)
    #定义测试用例集合
    allure_stories = ['--allure-stories']
    allure_stories_args = ['']
    allure_features = ['--allure-features']
    allure_features_args = ['Login']
    allure_path_args = ['--alluredir', report_dir, '--clean-alluredir']
    test_args = ['-vs', '-q']
    test_browser = 'firefox'  # chromium,webkit,firefox可选
    # run_browser = ['--browser ' + test_browser]
    run_args = test_args + allure_path_args + allure_features + allure_features_args + allure_stories + allure_stories_args
    result_code = pytest.main(run_args)
    #生成allure报告
    cmd = 'allure generate ./Report/ -o ./Report/allure-results --clean'
    log.info(cmd)
    os.system(cmd)
    # enviroment_info = [
    #     {"name": '版本号', "value": version}
    # ]
    # with open('./Report/allure-results/widgets/environment.json', 'w', encoding='utf-8') as f:
    #     json.dump(enviroment_info, f, ensure_ascii=False, indent=4)

    # 打印url
    # result_code = pytest.main()
    # url = '报告链接：http://127.0.0.1:63342/{}/Report/allure-results/index.html'.format(root_dir.split('/')[-1])
    # print(url)
    # ci判断是否全部执行
    if result_code == 0:
        sys.exit(0)
    else:
        sys.exit(1)


